<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script src="resources/js/jquery.json-2.4.js"></script>
<script type="text/javascript">
	function setInvoice() {
		var invoices = $("input[class=invoices]");
		var mygift_nos = $("input[class=mygift_nos]");
		var json = new Object();
		for(var i = 0; i < invoices.length; i++) {
			var temp = {
				mygift_no: mygift_nos[i].value,
				invoicenum: invoices[i].value
			};
			$(json).attr("invoices_"+i, temp);
		}
		
		$.ajax({
			url: "setInvoice.ga",
			type: "post",
			dataType: "html",
			data: {
				param: $.toJSON(json)
			},
			success: function(data) {
				alert(data);
			},
			error: function() {
				alert("오류");
			}
		});
	}
</script>

</head>
<body>

<p/>
<c:if test="${fn:length(winnerList) > 0 }">
<table class="list" cellspacing="0" cellpadding="5" style="text-align:center;width:100%;">
	<tr class="table_title">
		<td>등수</td>
		<td>날짜</td>
		<td>광고Title</td>
		<td>이름</td>
		<td>당첨자Id</td>
		<td>휴대폰번호</td>
		<td>주소</td>
		<td>우편번호</td>
		<td>경품번호(ID)</td>
		<td>경품명</td>
		<td>경품종류</td>
		<td>경품확인유무</td>
		<td>송장번호</td>
	</tr>
<c:forEach var="list" items="${winnerList }">
	<tr>
		<td>${list.rank }</td>
		<td>${fn:substring(list.gameendtime, 5, 13) }시</td>
		<td>${list.contents_title }</td>
		<td>${list.recipient }</td>
		<td>${list.id }</td>
		<td>
			${fn:substring( list.pnum , 0, 3 ) }-${fn:substring( list.pnum , 3, 7) }-${fn:substring( list.pnum, 7, 11) }
		</td>
		<td>${list.address_1 } &nbsp; ${list.address_2 }</td>
		<td>${list.zip }</td>
		<td>${list.giftId }</td>
		<td>${list.giftName }</td>
		<td>${list.giftType }</td>
		<td>
			<c:if test="${list.isreceive == true }">받기</c:if>
			<c:if test="${list.isreceive == false }">안받기</c:if>
			<c:if test="${list.isreceive == null }">미확인</c:if>
		</td>
		<td>
			<input type="text"
				id="invoice_${list.rank }"
				value="${list.invoicenum }"
				class="invoices"
				style="width:120px;"
			/>
			<input type="hidden"
				id="mygift_no_${list.rank }"
				value="${list.mygift_no }"
				class="mygift_nos"
			/>
		</td>
	</tr>
</c:forEach>
</table>
<br/>

<input type="button" value="입력완료"
	class="bigBtn"
	style="float:right;"
	onclick="setInvoice()"
	/>

</c:if>

<c:if test="${fn:length(winnerList) <= 0 }">
	<br/><br/><br/>
	<div style="width:100%;text-align:center;font-size:13pt;font-weight:bold;color:#666666;">당첨자가 없습니다.</div>
</c:if>

</body>
</html>